#include <stdio.h>
#include <math.h>

int main(){

	/* members declaration */

	// members for polynom 'ax^2 + bx + c'
	double a; 
	double b;
	double c;
	double d; // discriminant 

	/* get data from user */

	printf("Please enter the coefficient members for equation:\n");
	printf("Ax^2 + Bx + C\n\n");
	printf("enter \"A\" value:\n");
	scanf("%lf", &a);
	printf("enter \"B\" value:\n");
	scanf("%lf", &b);
	printf("enter \"C\" value:\n");
	scanf("%lf", &c);
	printf("\n");

	/* calculate discriminant*/
	d = pow(b,2) - (4 * a * c);
	
	/* print results to user */

	if (a != 0 ){
		//check discriminant
		if(d > 0) {
			double x1 = (-b + sqrt(pow(b,2) - (4 * a * c))) / (2 * a);
			double x2 = (-b - sqrt(pow(b,2) - (4 * a * c))) / (2 * a);
			printf("This polynom has two solutions\n");
			printf("X1 = %2.2lf\n", x1);
			printf("X2 = %2.2lf\n", x2);
		}
		else if (d == 0){
			double x1 = -(b/(2 * a));
			printf("This polynom has one solution\n");
			printf("X1 = %2.2lf\n", x1);
		}
		// complex numbers are manipulated as strings
		else {
			double real = -(b/(2 * a));
			double imag = (sqrt(-d))/(2*a);
			printf("this polynom has two complex solutions\n");
			printf("X1 = %2.2lf+%2.2fi\n", real,imag);
			printf("X2 = %2.2lf-%2.2fi\n", real,imag);
		}
	}
	//In case that a = 0
	//Straight line equation is calculated

	else {
		if (b != 0){
			double x1 = (-c/b);
			printf("There is one solution:\n");
			printf("X1 = %2.2lf\n", x1);
		}
		else {
			if (c != 0){
				printf("this polynom has no solution\n");
			}
			else {
				printf("this polynom has infinite solutions\n");
			}
		}
	}

	return 0;
}